using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace myIronPythonDemo
{
    /// <summary>
    /// Warning	1	Missing XML comment for publicly visible type or member 'myIronPythonDemo.CallTraceDialogbox'	C:\Documents and Settings\Joseph\My Documents\Visual Studio 2005\Projects\myIronPythonDemo1_4\myIronPythonDemo\CallTraceDialogbox.cs	11	26	myIronPythonDemo
    /// </summary>
    public partial class CallTraceDialogbox : Form
    {
        public CallTraceDialogbox()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Returns Error and Call Stack in a Dialogbox for easy cut and paste for taking notes.
        /// </summary>
        /// <param name="methodname">Method name</param>
        /// <param name="err_in">Exception error object</param>
        public void ShowTracesDlg(string methodname, Exception err_in)
        {
            string lastfilename = err_in.StackTrace;
            int pos = lastfilename.IndexOf("\r\n");
            if (pos != -1)
            {
                lastfilename = lastfilename.Substring(0, pos);
            }
            int line_length = lastfilename.Length;
            int pos_linenumber = lastfilename.IndexOf(":line");
            string linenumber = "";

            if (pos_linenumber != -1)
            {
                linenumber = lastfilename.Substring(pos_linenumber, line_length - pos_linenumber);
                lastfilename = lastfilename.Substring(0, pos_linenumber);
            }

            pos = lastfilename.LastIndexOf("\\");
            lastfilename = lastfilename.Remove(0, pos + 1);

            labelErr.Text = "Error: " + err_in.Message.ToString() + "\r\nMethod name that returned the Error: " + methodname + "\r\n" + "Error occurred in " + lastfilename + linenumber;
            tbCallstack.AppendText(err_in.Message.ToString() + "\r\nCall Stack: \r\n" + err_in.StackTrace);
            this.Show();
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}